package com.egu.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.egu.model.ClassSubject;
import com.egu.service.ClassSubjectService;
import com.egu.vo.PageParam;
import com.egu.vo.RequestPageVo;
import com.egu.vo.RequestResultVo;

@Controller
@RequestMapping("classSubject")
public class ClassSubjectController {

	@Autowired
	private ClassSubjectService classSubjectService;

	@RequestMapping("listUI")
	public String listUI() {
		return "classSubject/listUI";
	}

	@RequestMapping("/getList")
	@ResponseBody
	public RequestPageVo<ClassSubject> getList(@ModelAttribute(value = "param") PageParam param, ClassSubject classSubject) {
		RequestPageVo<ClassSubject> vo = classSubjectService.getList(param, classSubject);
		return vo;
	}

	@RequestMapping("/getAllList")
	@ResponseBody
	public RequestResultVo<List<ClassSubject>> getAllList() {
		RequestResultVo<List<ClassSubject>> vo = classSubjectService.getAllList();
		return vo;
	}
	
	
	
	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public RequestResultVo<ClassSubject> saveOrUpdate(ClassSubject classSubject) {
		RequestResultVo<ClassSubject> result = new RequestResultVo<ClassSubject>();
		if (classSubject != null) {
			return classSubjectService.saveOrUpdate(classSubject);
		} else {
			result.setSuccess(false);
		}
		return result;
	}

	@RequestMapping("/deleteDataById")
	public @ResponseBody RequestResultVo<ClassSubject> deleteDataById(@RequestParam(value = "id", required = false) Integer id) {
		RequestResultVo<ClassSubject> result = new RequestResultVo<ClassSubject>();
		if (id == null) {
			result.setSuccess(false);
			result.setErrorMessage("数据库操作异常");
			return result;
		}
		result = classSubjectService.deleteDataById(id);
		return result;
	}

}
